import java.util.LinkedList;
import java.util.List;

import play.test.*;
import models.*;


import org.junit.*;

import controllers.Tasks;
import play.test.UnitTest;
public class editProdcutBacklog extends UnitTest{

	@Test
	public void editTest(){
		Project p1=new Project("Test project",50,true,"test test test test").save();
		User Salma=new User("salma", "mohammed", "hamed", "salma7amed", "123", "salma.7amed@gmail.com",
    			"0118436337","habl","Cairo","Egypt","").save();
		Component comp1=new Component("C4","User Stories",p1).save();
    	UserStory x=new UserStory("Story", 50 , "High", comp1, Salma, null, null,"fixed").save();
    	UserStory edit = UserStory.findById(x.getEntityId());
		edit.status = "changed status";
		edit.effortEstimation = 18;
		edit.priority="Low";
		edit.story="testing edit in backlog";
		edit.save();
		assertNotNull(edit);
		assertTrue(edit.effortEstimation==18);
		assertTrue(edit.status.equals("changed status"));
		assertTrue(edit.story.equals("testing edit in backlog"));
		assertTrue(edit.priority.equals("Low"));
	}
	
	@Test
	public void editdependency(){
		Project p1=new Project("Test project",50,true,"test test test test").save();
		User Salma=new User("salma", "mohammed", "hamed", "salma7amed", "123", "salma.7amed@gmail.com",
    			"0118436337","habl","Cairo","Egypt","").save();
		Component comp1=new Component("C1","User Stories",p1).save();
		Component comp2=new Component("C2","User Stories",p1).save();
		Component comp3=new Component("C3","User Stories",p1).save();
		List<Component> z= new LinkedList<Component>();
	 	UserStory x=new UserStory("Story", 50 , "High", comp1, Salma, null,z ,"fixed").save();
	 	x.dependOnComponents.add(comp2);
	 	Component comp=Component.find("byName","C3").first();
		 Component old=Component.findById(comp2.getEntityId());
		 UserStory edit = UserStory.findById(x.getEntityId());
		 List<Component> component= p1.components;
		 for( int i=0 ; i<component.size() ; i++){
				if("C3"==component.get(i).name)
					comp=component.get(i);
		 }				
		edit.dependOnComponents.add(comp);
		edit.dependOnComponents.remove(old);
		edit.save();
		assertTrue(edit.dependOnComponents.contains(comp3));
		assertTrue(edit.dependOnComponents.get(0).equals(comp3));
	}
}
